﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using Defecter.Gui.Access;
using DefectDBTypes;
using System.IO;



namespace Defector
{
    /// <summary>
    /// Interaction logic for Login.xaml
    /// </summary>
    public partial class addCompany : Window
    {

        public SqlConnection con;
        SqlDataAdapter adapter = new SqlDataAdapter();

        public addCompany()
        {
            InitializeComponent();
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void createbtn_Click(object sender, RoutedEventArgs e)
        {
            //Check to see if form is completely filled out
            if (nameinput.Text != "" && phoneinput.Text != "" && addressinput.Text != "")
            {

                string sqlIns = "INSERT INTO Companies (Company_Name, Company_Phone, Company_Address) VALUES (@Company_Name, @Company_Phone, @Company_Address)";

                try
                {
                    con.Open();
                    SqlCommand cmdIns = new SqlCommand(sqlIns, con);
                    cmdIns.Parameters.AddWithValue("@Company_Name", nameinput.Text);
                    cmdIns.Parameters.AddWithValue("@Company_Phone", phoneinput.Text);
                    cmdIns.Parameters.AddWithValue("@Company_Address", addressinput.Text);
                    cmdIns.ExecuteNonQuery();
                    cmdIns.Dispose();
                    cmdIns = null;
                    con.Close();
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An error occurred while adding the company.");
                }
            }
            else
                MessageBox.Show("Please complete the form!");
        }

    }
}
